#include "GCREWnd.h"

#include <map>
#include "resource.h"
#include "BasicType/BasicType.h"
#include "Math/Math.h"
#include "SceneModel/SceneModelManipulator.h"

using namespace GCRE;
using namespace GCRE::BasicType;
using namespace GCRE::SceneModel;

CGCREWnd::CGCREWnd()
{

}

CGCREWnd::~CGCREWnd()
{
	
}

void CGCREWnd::OnLButtonDown( UINT nFlags, int x, int y )
{
	SFFloat inv_ir_1[] = { 0.996807, -0.012389, 0.078885, 66.749432, 
		0.015995, 0.998848, -0.045245, 73.844276, 
		-0.078233, 0.046362, 0.995856, -431.387078, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	SFFloat inv_color_1[] = { 0.998465, -0.005950, 0.055068, 35.147302, 
		0.007176, 0.999730, -0.022105, 77.096287, 
		-0.054922, 0.022467, 0.998238, -431.984527, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	Matrix44f inv_ir_m( inv_ir_1 );
	Matrix44f color_m( inv_color_1 );
	color_m.Inverse();
	Matrix44f m = color_m * inv_ir_m;
	m.Print();

	SFFloat inv_ir_2[] = { -0.726918, -0.024009, 0.686305, -278.571012, 
		-0.036578, 0.999324, -0.003784, 65.950795, 
		-0.685750, -0.027854, -0.727304, 441.988608, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	SFFloat inv_color_2[] = { -0.701889, -0.049895, 0.710537, -263.767231, 
		-0.043918, 0.998677, 0.026746, 68.464855, 
		-0.710931, -0.012433, -0.703152, 464.668248, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	inv_ir_m.SetMatrix( inv_ir_2 );
	color_m.SetMatrix( inv_color_2 );
	color_m.Inverse();
	m = color_m * inv_ir_m;
//	m.Print();

	SFFloat inv_ir_3[] = { -0.669513, 0.027330, -0.742297, 515.338974, 
		0.069234, 0.997269, -0.025729, 80.193419, 
		0.739567, -0.068618, -0.669576, 524.329034, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	SFFloat inv_color_3[] = { -0.696626, 0.043425, -0.716119, 536.012296, 
		0.058541, 0.998279, 0.003588, 78.514266, 
		0.715042, -0.039422, -0.697969, 508.632733, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	inv_ir_m.SetMatrix( inv_ir_3 );
	color_m.SetMatrix( inv_color_3 );
	color_m.Inverse();
	m = color_m * inv_ir_m;
//	m.Print();

	SFFloat inv_ir_4[] = { -0.901449, -0.012960, 0.432692, -106.779663, 
		-0.019090, 0.999769, -0.009826, 71.258685, 
		-0.432465, -0.017118, -0.901488, 603.101074, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	SFFloat inv_color_4[] = { -0.887645, -0.031011, 0.459483, -83.321631, 
		-0.029572, 0.999509, 0.010330, 80.200651, 
		-0.459578, -0.004418, -0.888127, 622.328914, 
		0.000000, 0.000000, 0.000000, 1.000000 };
	inv_ir_m.SetMatrix( inv_ir_4 );
	color_m.SetMatrix( inv_color_4 );
	color_m.Inverse();
	m = color_m * inv_ir_m;
//	m.Print();

	SFFloat K_ir[] = {583.597204f, 0.0f, 328.047358f, 0.0f, 
							0.0f, 583.908335f, 247.759493f, 0.0f, 
							0.0f, 0.0f, 1.0f, 0.0f, 
							0.0f, 0.0f, 0.0f, 1.0f };
	Matrix44f inv_K_ir( K_ir );
	inv_K_ir.Print();
	inv_K_ir.Inverse();
	inv_K_ir.Print();

}

BOOL CGCREWnd::PreCreateWindow( CREATESTRUCT& cs )
{
	HICON hIcon = ::LoadIcon( cs.hInstance, MAKEINTRESOURCE(IDI_ENGINE) );
	
	SetIcon( hIcon, TRUE );
	SetIcon( hIcon, FALSE );

	return TRUE;
}

int CGCREWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
	if ( CWin32Window::OnCreate( lpCreateStruct ) != 0 )
		return -1;

	return 0;
}

BOOL CGCREWnd::OnCommand( WPARAM wParam, LPARAM lParam )
{
	switch( LOWORD(wParam) )
	{
		default:
			break;
	}
	return TRUE;
}
